package edu.zzuli.assistant.dao.impl;

import org.hibernate.Query;
import org.hibernate.Session;
import edu.zzuli.assistant.bean.Admin;
import edu.zzuli.assistant.dao.AdminDao;
import edu.zzuli.assistant.until.HibernateUtil;
import edu.zzuli.assistant.until.MD5Utiil;

public class AdminDaoImpl implements AdminDao {

	@Override
	public Admin exists(Admin admin) {
		
		Session session=HibernateUtil.getCurrentSession();
		String hql = "from Admin admin where admin.id=? and admin.password=?";
		Query query=session.createQuery(hql);
		query.setString(0, admin.getId());
		query.setString(1, MD5Utiil.encrypt16(admin.getPassword()));
		admin = (Admin) query.uniqueResult();
		return admin;
	}

	@Override
	public boolean modifyPassword(Admin admin, String newPassword) {
		// TODO Auto-generated method stub
		String hql = "update Admin admin set admin.password=? where admin.id=?";
		Session session = HibernateUtil.getCurrentSession();
		Query query = session.createQuery(hql);
		query.setString(0,MD5Utiil.encrypt16(newPassword) );
		query.setString(1, admin.getId());
		query.executeUpdate();
		return false;
	}
	

}
